﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using Projectmanagement.Utl;

namespace Projectmanagement.Entity
{
    public class TaskComment : EntityBase
    {
        [Display(Name = "提交人"), Required]
        public string Submitter { get; set; }

        [Display(Name = "内容"), Required]
        public string Contents { get; set; }

        [Display(Name = "评论日期"), Required]
        public DateTime CommentDate { get; set; }

        public int? TaskID { get; set; }
    }

    public class TaskState : EntityBase
    {
        [Display(Name = "任务状态名称"), Required]
        public string Name { get; set; }

        [Display(Name = "任务状态编码"), Required]
        public int Code { get; set; }
    }

    public class TaskTemplate : EntityBase
    {
        [Display(Name = "任务默认选中"), Required]
        public bool IsDefault { get; set; }

        [Display(Name = "任务名称"), Required]
        public string Name { get; set; }

        [Display(Name = "任务描述"), Required]
        public string Content { get; set; }

        [Display(Name = "倒推天数"), Required]
        public int DateCount { get; set; }

        [Display(Name = "总天数")]
        public int Duration { get; set; }

        [Display(Name = "里程碑"), Required]
        public int? MilestoneID { get; set; }

        //[Display(Name = "任务执行角色"), Required]
        //public string Roles { get; set; }

        [Display(Name = "知识库链接")]
        public string KMLinks { get; set; }

        [Display(Name = "可交付成果")]
        public string Deliverables { get; set; }

        //[Display(Name = "任务执行人"), Required]
        //public string Owners { get; set; }

        public virtual RolePM RolePM
        {
            get;
            set;
        }

        [Display(Name = "任务执行人"), Required]
        public int? RolePMID
        {
            get;
            set;
        }

        [Display(Name = "完成度"), Range(0, 1), Required]
        public double Complement { get; set; }

    }

    public class Task : EntityBase
    {
        [Display(Name = "知识库链接")]
        public string KMLinks { get; set; }

        [Display(Name = "可交付成果描述")]
        public string Deliverables { get; set; }

        public virtual Project Project { get; set; }
        [Display(Name = "所属项目"), Required]
        public int? ProjectID { get; set; }

        [Display(Name = "所属里程碑")]
        public int? MilestoneID { get; set; }
        public virtual Milestone Milestone { get; set; }

        [Display(Name = "任务名称"), Required]
        public string Name { get; set; }

        [Display(Name = "任务描述"), Required]
        public string Content { get; set; }

        [Display(Name = "任务知会")]
        public string Notify { get; set; }

        [Display(Name = "总天数")]
        public int Duration { get { return (EndDate - StartDate).Days; } }

        [Display(Name = "开始时间"), Required]
        public DateTime StartDate { get; set; }

        [Display(Name = "结束时间"), Required]
        public DateTime EndDate { get; set; }

        [Display(Name = "任务执行人"), Required]
        public string Owners { get; set; }

        //[Display(Name = "完成度"), Range(0,1),Required]
        //public double Complement { get; set; }

        [Display(Name = "任务状态")]
        public int? TaskStateID { get; set; }
        public virtual TaskState TaskState { get; set; }

        [Display(Name = "实际完成时间")]
        public DateTime? FinishDate { get; set; }

        [Display(Name = "任务发放人")]
        public string Assinger { get; set; }

        public string FinishPer
        {
            get
            {
                return this.FinishDate == null
                    ? ((DateTime.Now - this.StartDate).Days + "/" + Duration)
                    : ((Convert.ToDateTime(this.FinishDate) - this.StartDate).Days + "/" + Duration);
            }
        }

        //public string GetFileNames
        //{
        //    get
        //    {
        //        var data = (from x in CH.DB.TaskFiles
        //            where x.TaskId == this.ID
        //            select x.FileName).ToArray();
        //        return string.Join(";", data);
        //    }
        //}

        public virtual List<TaskFile> TaskFiles { get; set; }

        [Display(Name = "任务编号")]
        public string TaskCode { get; set; }


    }

    public class TaskTrack : EntityBase
    {
        [Display(Name = "任务")]
        public int? TaskId { get; set; }

        [Display(Name = "原执行人")]
        public string OldOwners { get; set; }

        [Display(Name = "新执行人")]
        public string NewOwners { get; set; }

        [Display(Name = "原状态")]
        public string OldState { get; set; }

        [Display(Name = "新状态")]
        public string NewState { get; set; }

        [Display(Name = "说明")]
        public string Content { get; set; }
    }

    public class TaskFile : EntityBase
    {
        [Display(Name = "任务")]
        public int? TaskId { get; set; }

        [Display(Name = "文件名")]
        public string FileName { get; set; }

        [Display(Name = "文件地址")]
        public string FileUrl { get; set; }

        public virtual Task Task { get; set; }
    }

    public class UploadFile : EntityBase
    {
        [Display(Name = "文件")]
        public int? FileID { get; set; }

        [Display(Name = "文件名")]
        public string FileName { get; set; }

        [Display(Name = "文件地址")]
        public string FileUrl { get; set; }
        [Display(Name = "文件类型")]
        public string FileType { get; set; }

    }

    public class TaskTemplateType : EntityBase
    {
        public string Name { get; set; }
    }
}